﻿using System.Collections.Generic;
using KSS.Generator.Schema;
using System.IO;

namespace KSS.Generator
{
    public class GeneratorContext
    {
        private Configuration.GeneratorSetting _setting;
        public Configuration.GeneratorSetting Setting
        {
            get { return _setting; }
            set { _setting = value; }
        }

        private Database _databaseSchema;
        public Database DatabaseSchema
        {
            get { return _databaseSchema; }
            set { _databaseSchema = value; }
        }

        private List<DirectoryInfo> _templateDirectories;
        public List<DirectoryInfo> TemplateDirectories
        {
            get
            {
                if (_templateDirectories == null)
                {
                    _templateDirectories = new List<DirectoryInfo>();
                }

                return _templateDirectories;
            }
        }

        private List<DirectoryInfo> _generatedDirectories;
        public List<DirectoryInfo> GeneratedDirectories
        {
            get
            {
                if (_generatedDirectories == null)
                {
                    _generatedDirectories = new List<DirectoryInfo>();
                }

                return _generatedDirectories;
            }
        }

        /// <summary>
        /// Get template directory information
        /// </summary>
        /// <param name="templateDirectoryName"></param>
        /// <returns></returns>
        public DirectoryInfo GetTemplateDirectory(string templateDirectoryName)
        {
            DirectoryInfo dirProjectTemplate = TemplateDirectories.Find(
                delegate(DirectoryInfo d)
                {
                    return (d.Name == templateDirectoryName);
                });

            return dirProjectTemplate;
        }

        /// <summary>
        /// Get generated directory information
        /// </summary>
        /// <param name="generatedDirectoryName"></param>
        /// <returns></returns>
        public DirectoryInfo GetGeneratedDirectory(string generatedDirectoryName)
        {
            DirectoryInfo dirGenerated = GeneratedDirectories.Find(
                delegate(DirectoryInfo d)
                {
                    return (d.Name == generatedDirectoryName);
                });

            return dirGenerated;
        }
    }
}
